package com.leyu.mall.admin.cms.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.leyu.mall.common.model.NewsModel;
import com.leyu.mall.domain.cms.CmsChannel;
import com.leyu.mall.domain.cms.CmsNews;
import com.leyu.mall.domain.cms.CmsNewsType;
import com.leyu.mall.service.cms.ICmsNewsTypeService;
/**
 * 〈一句话功能简述〉 〈功能详细描述〉
 * @author OOKK
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@Scope(value = "singleton")
@RequestMapping("admin/newstype")
public class CmsNewsTypeController
{
	 
	
	@Resource 
	private ICmsNewsTypeService		cmsNewsTypeServiceImpl;
	
	
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public String save(Model model, CmsNewsType cmsNewsType)
	{
		try
		{
			cmsNewsTypeServiceImpl.save(cmsNewsType);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect:../newstype";
	}

	@RequestMapping(value = "delete/{newsTypeId}", method = RequestMethod.GET)
	public String delete(Model model, @PathVariable long newsTypeId)
	{
		try
		{
			cmsNewsTypeServiceImpl.deleteCmsNewsType(newsTypeId);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect:../../newstype";
	}

	@RequestMapping(value = "edit/{newsTypeId}", method = RequestMethod.GET)
	public String edit(Model model, @PathVariable long newsTypeId)
	{
		try
		{
//			model.addAttribute("channellist", cmsChannelService.getcmsChannelList());
//			model.addAttribute("entity", cmsNewsTypeServiceImpl.getCmsNewsById(newsId));
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "admin/editnewstype.html";
	}

	@ExceptionHandler(Exception.class)
	public String exception(Exception e, HttpServletRequest request)
	{
		request.setAttribute("exception", e);
		return "/error.html";
	}

	@RequestMapping(value = "new", method = RequestMethod.GET)
	public String newNews(Model model) throws Exception
	{
		
//		model.addAttribute("channellist", cmsChannelService.getcmsChannelList());
		model.addAttribute("newstypelist", cmsNewsTypeServiceImpl.getCmsNewsTypeList());
		return "admin/newnewstype.html";
	}

	@RequestMapping(value = "", method = RequestMethod.GET)
	public String index(Model model,@RequestParam(value = "curPage", required = false, defaultValue ="1" ) int curPage) throws Exception
	{
		try
		{
			model.addAttribute("newstypelist", cmsNewsTypeServiceImpl.getCmsNewsTypeList());
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "admin/newstype.html";
	}
}
